package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

import java.util.Calendar;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/valid-perfect-square/">367. 有效的完全平方数</a>
 */
public class Solution367 extends BaseSolution {

    public boolean isPerfectSquare(int num) {
        int left = 1;
        int right = num;
        while (left <= right) {
            int mid = (right - left) / 2 + left;
            long sq = (long) mid * mid;
            if (sq == num) {
                return true;
            } else if (sq < num) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        Solution367 solution = new Solution367();
        System.out.println(solution.isPerfectSquare(Integer.MAX_VALUE));
    }
}